home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP10 / NOPOPUPS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  3.5 KB  |  107 lines

  1. /*-------------------------------------------------
  2.    NOPOPUPS.C -- Demonstrates No-Popup Nested Menu
  3.                  (c) Charles Petzold, 1996
  4.   -------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include "nopopups.h"
  8.  
  9. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  10.  
  11. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  12.                     PSTR szCmdLine, int iCmdShow)
  13.      {
  14.      static char szAppName[] = "NoPopUps" ;
  15.      HWND        hwnd ;
  16.      MSG         msg ;
  17.      WNDCLASSEX  wndclass ;
  18.  
  19.      wndclass.cbSize        = sizeof (wndclass) ;
  20.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  21.      wndclass.lpfnWndProc   = WndProc ;
  22.      wndclass.cbClsExtra    = 0 ;
  23.      wndclass.cbWndExtra    = 0 ;
  24.      wndclass.hInstance     = hInstance ;
  25.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  26.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  27.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  28.      wndclass.lpszMenuName  = NULL ;
  29.      wndclass.lpszClassName = szAppName ;
  30.      wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;
  31.  
  32.      RegisterClassEx (&wndclass) ;
  33.  
  34.      hwnd = CreateWindow (szAppName, "No-Popup Nested Menu Demonstration",
  35.                           WS_OVERLAPPEDWINDOW,
  36.                           CW_USEDEFAULT, CW_USEDEFAULT,
  37.                           CW_USEDEFAULT, CW_USEDEFAULT,
  38.                           NULL, NULL, hInstance, NULL) ;
  39.  
  40.      ShowWindow (hwnd, iCmdShow) ;
  41.      UpdateWindow (hwnd) ;
  42.  
  43.      while (GetMessage (&msg, NULL, 0, 0))
  44.           {
  45.           TranslateMessage (&msg) ;
  46.           DispatchMessage (&msg) ;
  47.           }
  48.      return msg.wParam ;
  49.      }
  50.  
  51. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  52.      {
  53.      static HMENU hMenuMain, hMenuEdit, hMenuFile ;
  54.      HINSTANCE    hInstance ;
  55.  
  56.      switch (iMsg)
  57.           {
  58.           case WM_CREATE :
  59.                hInstance = (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) ;
  60.  
  61.                hMenuMain = LoadMenu (hInstance, "MenuMain") ;
  62.                hMenuFile = LoadMenu (hInstance, "MenuFile") ;
  63.                hMenuEdit = LoadMenu (hInstance, "MenuEdit") ;
  64.  
  65.                SetMenu (hwnd, hMenuMain) ;
  66.                return 0 ;
  67.  
  68.           case WM_COMMAND :
  69.                switch (LOWORD (wParam))
  70.                     {
  71.                     case IDM_MAIN :
  72.                          SetMenu (hwnd, hMenuMain) ;
  73.                          return 0 ;
  74.  
  75.                     case IDM_FILE :
  76.                          SetMenu (hwnd, hMenuFile) ;
  77.                          return 0 ;
  78.  
  79.                     case IDM_EDIT :
  80.                          SetMenu (hwnd, hMenuEdit) ;
  81.                          return 0 ;
  82.  
  83.                     case IDM_NEW :
  84.                     case IDM_OPEN :
  85.                     case IDM_SAVE :
  86.                     case IDM_SAVEAS :
  87.                     case IDM_UNDO :
  88.                     case IDM_CUT :
  89.                     case IDM_COPY :
  90.                     case IDM_PASTE :
  91.                     case IDM_DEL :
  92.                          MessageBeep (0) ;
  93.                          return 0 ;
  94.                     }
  95.                break ;
  96.  
  97.           case WM_DESTROY :
  98.                SetMenu (hwnd, hMenuMain) ;
  99.                DestroyMenu (hMenuFile) ;
  100.                DestroyMenu (hMenuEdit) ;
  101.  
  102.                PostQuitMessage (0) ;
  103.                return 0 ;
  104.           }
  105.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  106.      }
  107.